package com.sicheng.lc.周赛.分类.哈西表or计数or滑动窗口or双指针.计数;

import java.util.HashMap;

/**
 * @author zsc
 * @version 1.0
 * @date 2022/6/22 12:18
 */
public class 完成所有任务需要的最少轮数 {
    //https://leetcode.cn/problems/minimum-rounds-to-complete-all-tasks/
    public int minimumRounds(int[] tasks) {
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int task : tasks) {
            map.put(task, map.getOrDefault(task, 0) + 1);
        }
        int count = 0;
        for (int x : map.values()) {
            if (x < 2) {
                return -1;
            }
            if (x % 3 == 0) {
                count += x / 3;
            } else {
                count += x / 3 + 1;
            }
        }
        return count;
    }
}
